
// jquery scripts
$(function() {
	initJQuery();
});
function initJQuery(){
	//$("tr").colorBlend(myColors);
	//alert('s');
	$(".codeExamples").each(function (){
		$("#"+this.id).bind('focus',function(event){
			$("#"+this.id).colorBlend(col_fadeIn);
			$("#"+this.id+"_err").fadeOut();
		});
		$("#"+this.id).bind('blur',function(event){
			$("#"+this.id).colorBlend(col_fadeOut);
			switch(this.id){
				case "pkg":
				if ($("#pkg").val().length<1){
					$("#pkg").after("<span id='pkg_err' class='error'> ERROR</span>");
				}else{
					$("#pkg_err").fadeOut();
				}
				break;
				case "tbl":
				if ($("#tbl").val().length<1){
					$("#tbl").after("<span id='tbl_err' class='error'> ERROR</span>");
				}else{
					$("#tbl_err").fadeOut();
				}
				break;
				case "clas":
				if ($("#clas").val().length<1){
					$("#clas").after("<span id='clas_err' class='error'> ERROR</span>");
				}else{
					$("#clas_err").fadeOut();
				}
				break;
			}
		});
	})

	$("#helpClick").bind('mouseover',function (event){$('#help_tr').show(250)});
	$("#helpClick").bind('mouseout',function (event){$('#help_tr').hide(250)});
	$("#type").bind('change',function(e){
		if ($("#"+this.id).val()=="ENUM"){
			$("#enum").show(350);
		}else{
			$("#enum").hide(350);
		}
	});
}

var col_fadeIn = [
{param:'color', fromColor:"#003399", toColor:"#ff0000", duration:250},
{param:'background-color',  fromColor:"#f0f0f0", toColor:"#ffffee", duration:250}
];
var col_fadeOut = [
{param:'color', fromColor:"#ff0000", toColor:"#003399", duration:650},
{param:'background-color',  fromColor:"#ffffee", toColor:"#f0f0f0", duration:650}
];

// END OF JQUERY STUFF


function addF(){

	var k = document.aa;
	var err = false;
	//check for inconsistencies
	// check required fields
	if (k.fname.value.length<1){
		k.fname.focus();
		err=true;
	}
	// end required
	// NO NAME FOR FORM? Use Field Name
	if (k.vars.value.length<1){
		k.vars.value=k.fname.value;
	}

	// TEXT should not have length;
	if (k.type[k.type.selectedIndex].value=="TEXT"){
		k.length.value='';
		k.extra.selectedIndex=0;
	}

	// check for ENUM
	if (k.type[k.type.selectedIndex].value=="ENUM"){
		var ar = k.defaults.value.split(",");
		if (ar.length<2){
			err=true;
			alert('READ THE INSTRUCTIONS FOR ENUM/RADIO');
		}else{
			for(var i=0;i<ar.length;i++){
				if (ar[i].indexOf("'")<1){
					//good let me add the things for you
					ar[i]="'" + ar[i] + "'";
				}
			}
			k.defaults.value = ar.join(",")
		}
	}


	// end check
	if (!err){


		line ="";
		line += "@var:"+k.vars.value;
		line += ":"+k.fname.value;
		line += ":"+k.type[k.type.selectedIndex].value;
		line += ":"+k.length.value;
		line += ":"+k.defaults.value;
		line += ":"+k.extra[k.extra.selectedIndex].value;
		line += ":"+(k.pk.checked?"PRIMARY_KEY":"");
		k.pane.value +=line+"\r\n";
	}
}
function clear(){
	var k = document.aa;
	k.vars.value="";
	k.fname.value="";
	k.type.selectedIndex=0;
	k.length.value="";
	k.defaults.value="";
	k.extra.selectedIndex=0;
	k.pk.checked=false;
}
function clearAll(){
	var k = document.aa;
	clear();
	k.pane.value="";
}
function adC(){
	addF();
	clear();
}
function fisnish(){
	var k = document.aa;
	error=false;
	//alert($("#pkg_err"))
	if (k.pkg.value.length<1){
		$("#pkg_err").remove();
		$("#pkg").after("<span id='pkg_err' class='error'> ERROR</span>");
		error=true;
	}
	if (k.tbl.value.length<1){
		$("#tbl_err").remove();
		$("#tbl").after("<span id='tbl_err' class='error'> ERROR</span>");
		error=true;
	}
	if (k.clas.value.length<1){
		$("#clas_err").remove();
		$("#clas").after("<span id='clas_err' class='error'> ERROR</span>");
		error=true;
	}
	if (!error){
		nl = "";
		nl += "@php\r\n";
		nl += "@mysql\r\n";
		nl += "@TABLE:" + k.tbl.value + "\r\n";
		nl += "@package:" + k.pkg.value + "\r\n";
		nl += "@class:" + k.clas.value + "\r\n";
		nl += "@desc:" + k.dsc1.value + "\r\n";
		nl += "@desc:" + k.dsc2.value + "\r\n";
		nl += "@desc:" + k.dsc3.value + "\r\n";
		nl += "@author:" + k.ath.value + "\r\n";
		nl += k.pane.value;
		k.pane.value=nl;
		k.submit();
	}
}